from .table import CatalogTableForm, CatalogTable
from .index import CatalogIndex, CatalogIndexForm
from .function import CatalogFunction, CatalogFunctionForm

# mock
catalog_table = CatalogTable()
catalog_index = CatalogIndex()
catalog_function = CatalogFunction()

# catalog_table.insert(CatalogTableForm('t1', ['id', 'name'], [int, str]))
# catalog_table.insert(CatalogTableForm('t2', ['id', 'name', 'address'], [int, str, str]))
# 在t1表的id列常见idx索引
# catalog_index.insert(CatalogIndexForm('idx', 'id', 't1'))


def init_catalog():
    catalog_table.load()
    catalog_table.load()
    # 添加内置函数
    # 'count': len,
    # 'sum': sum,
    # 'max': max,
    # 'avg': (lambda x: sum(x) / len(x))
    catalog_function.insert(CatalogFunctionForm(function_name='count', arg_num=-1, callback=len, is_agg=True))
    catalog_function.insert(CatalogFunctionForm(function_name='sum', arg_num=-1, callback=sum, is_agg=True))
    catalog_function.insert(CatalogFunctionForm(function_name='max', arg_num=-1, callback=max, is_agg=True))
    catalog_function.insert(CatalogFunctionForm(function_name='min', arg_num=-1, callback=min, is_agg=True))
    catalog_function.insert(
        CatalogFunctionForm(function_name='avg', arg_num=-1, callback=(lambda x: sum(x) / len(x)), is_agg=True)
    )
